package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.HomeDetailInfo;
import com.tenglong.teacher.ui.adapter.viewholder.HomeworkContentViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.HomeworkListViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hdx on 2019/5/21.
 */
public class HomeworkListAdapter extends RecyclerView.Adapter<BaseViewHolder<HomeDetailInfo>> {

    private List<HomeDetailInfo> infos;
    private HomeworkListViewHolder.OnViewHideListener listener;
    public HomeworkListAdapter(List<HomeDetailInfo> infos,HomeworkListViewHolder.OnViewHideListener listener) {
        this.infos = infos;
        this.listener=listener;
        integerMap=new HashMap<>();
    }
    private Map<Integer,Integer> integerMap;
    private ViewGroup.LayoutParams layoutParams ;
    public static boolean isCheck=true;
    @NonNull
    @Override
    public BaseViewHolder<HomeDetailInfo> onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if (i == 0) {
            return new HomeworkContentViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.homework_content, viewGroup, false));
        } else {
            return new HomeworkListViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.homework_list_item, viewGroup, false),infos.size(),listener);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return infos.get(position).isTeacherPublishHomework?0:1;
    }
    public void setIntegerMap(Map<Integer, Integer> integerMap) {
        this.integerMap = integerMap;
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<HomeDetailInfo> holder, int position) {
        layoutParams= holder.itemView.getLayoutParams();
        if(!integerMap.containsKey(position)){
            holder.itemView.setVisibility(View.VISIBLE);
            layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        }else{
            holder.itemView.setVisibility(View.GONE);
            layoutParams.height = 0;
        }
        holder.itemView.setLayoutParams(layoutParams);
        holder.setLayoutInfo(infos.get(position));
    }

    @Override
    public int getItemCount() {
        return infos.size();
    }
}
